package com.code.demo.ui.common;

import android.content.Context;
import android.widget.Toast;

/**
 * Toast类，同一页面的Toast命令只显示最后一条信息
 * 
 * @author gufanghua alter by czh
 */

public class ToastFactory
{
    private Context context = null;
    private Toast toast = null;

    private static final ToastFactory toastFactory = new ToastFactory();

    private ToastFactory()
    {

    }

    /**
     * @param context 使用时的上下文
     * @param hint Toast
     */
    public static void showToast(Context context, String hint)
    {

        if (toastFactory.context == context)
        {
            toastFactory.toast.setText(hint);
        }
        else
        {
            toastFactory.context = context;
            toastFactory.toast = Toast.makeText(context, hint, Toast.LENGTH_SHORT);
        }

        toastFactory.toast.show();
    }

    public static Toast getToast(Context context)
    {
        Toast tst = null;
        if (toastFactory.context == context)
        {
            tst = toastFactory.toast;
        }

        return tst;
    }
}
